<?php

session_start();

/* for localhost */
//$parentDir = dirname(dirname(__FILE__));
require_once 'pdf2text.php';
require_once 'dataAccess.php';
if($_FILES['file1']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file1']['name'];
	$_SESSION['file1'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file1']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "a";
	} else {
		echo $_SESSION['file1'];
	}
}

if($_FILES['file2']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file2']['name'];
	$_SESSION['file2'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file2']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "b";
	} else {
		echo $_SESSION['file2'];
	}
}

if($_FILES['file3']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file3']['name'];
	$_SESSION['file3'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file3']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "c";
	} else {
		echo $_SESSION['file3'];
	}
}

if($_FILES['file4']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file4']['name'];
	$_SESSION['file4'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file4']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "d";
	} else {
		echo $_SESSION['file4'];
	}
}

if($_FILES['file5']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file5']['name'];
	$_SESSION['file5'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file5']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "e";
	} else {
		echo $_SESSION['file5'];
	}
}

if($_FILES['file6']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file6']['name'];
	$_SESSION['file6'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file6']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "f";
	} else {
		echo $_SESSION['file6'];
	}
}

if($_FILES['file7']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file7']['name'];
	$_SESSION['file7'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file7']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "g";
	} else {
		echo $_SESSION['file7'];
	}
}

if($_FILES['file8']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file8']['name'];
	$_SESSION['file8'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file8']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "h";
	} else {
		echo $_SESSION['file8'];
	}
}

if($_FILES['file9']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file9']['name'];
	$_SESSION['file9'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file9']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "i";
	} else {
		echo $_SESSION['file9'];
	}
}

if($_FILES['file10']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file10']['name'];
	$_SESSION['file10'] = $sourcename;
	$file_name = "../uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file10']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);							
	}
	if ($ext == "doc")
	{				
		$content = "WORD FILE CONTENT";				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		//$da->addPdfWordTerm($content, $file_name, $file_name, date("Y"), $userName);	// old							
		$da->addPdfWordTerm($content, $sourcename, date("Y"), $userName, $_SESSION['user_id']);
	}
	
	if($err == 1) {
		echo "j";
	} else {
		echo $_SESSION['file10'];
	}
}

/* for www.studysage.com.au */
//$parentDir = dirname(dirname(__FILE__));
/*require_once 'pdf2text.php';
require_once 'dataAccess.php';
if($_FILES['file1']['name'])
{
	if (!is_dir("../uploads"))
  	{
  		mkdir("../uploads");
  	}
	  	if (!is_dir("../uploads/assignment"))
  	{
  		mkdir("../uploads/assignment");
  	}

	$rand=date("Ymdhis");
	$sourcename = "assignment_".$rand."_".$_FILES['file1']['name'];
	$_SESSION['file1'] = $sourcename;
	$file_name = "uploads/assignment/".$sourcename;			
	move_uploaded_file($_FILES['file1']['tmp_name'], $file_name);			
	$ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));			
	if ($ext == "pdf")
	{				
		$content = trim(pdf2text($file_name));				
		$content = preg_replace('/\r|\n/', "", $content);				
		$da = new dataAccess();				
		$userName = $da->getFirstNameByID($_SESSION['user_id']);
		$da->addPdfTerm($content, $file_name, $file_name, date("Y"), $userName);								
	}			
}*/

?>